﻿using Guoc.BigMall.Web.Services;
using Guoc.BigMall.WebService;
using Guoc.BigMall.WebService.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Guoc.BigMall.Web.Controllers
{
    public class MemberAddressController : Controller
    {
        IMemberAddressService _memberService;
        public MemberAddressController(IMemberAddressService memberService)
        {
            this._memberService = memberService;
        }

        public ActionResult Index(int memberId)
        {
            var rows = _memberService.GetAddressList(memberId);           
            return new JsonNetResult(ResultModel.Ok(new { list = rows}));
        }

        public ActionResult Default(int memberId)
        {
            var rows = _memberService.GetDefaultAddress(memberId);
            return new JsonNetResult(ResultModel.Ok(rows));
        }

        public ActionResult Detail(int addressId)
        {
            var model = _memberService.GetById(addressId);
            return new JsonNetResult(ResultModel.Ok(model));
        }

        public ActionResult Save(MemberAddressDto model)
        {
            var id = _memberService.CreateOrUpdate(model);
            return new JsonNetResult(ResultModel.Ok(id));
        }
        public ActionResult Delete(int addressId)
        {
            _memberService.Delete(addressId);
            return new JsonNetResult(ResultModel.Ok());
        }

    }
}